******************************************************
* Title: rwanda_headteacher_endline_jde.do
* Author: Todd Pugatch
* Last update: June 10 2024
* 
* Description: data cleaning for Blimpo and Pugatch, "Entrepreneurship Education
*	and Teacher Training in Rwanda," Stage 2 Registered report, Journal of 
*	Development Economics
*
* Inputs: headteacher_endline_clean_NOPIIs.dta
* Outputs: headteacher_endline_clean_jde.dta
*
* Notes: cleans head teacher endline survey
*******************************************************

* Set environment
local start=`"$S_TIME"'
clear
clear matrix
clear mata
graph drop _all
program drop _all
cap log close
set more off

* Set directories 
*global main "[SET MAIN DIRECTORY HERE]"
	global rawdata "$main/01_data/01_raw"
	global cleandata "$main/01_data/02_clean"
	global dofiles "$main/02_dofiles"
	global results "$main/03_results"
	global out "$main/04_output"

* define exchange rate to convert all variables in FRW into USD
local xrate=868.0579 

*exchange rate on 1 July 2018: http://www.exchangerates.org.uk/USD-RWF-exchange-rate-history-full.html*/

*********************************************************************
* 					LOAD AND PREPARE DATA
*
* 	variable naming and label conventions: 
*	--names:	use [bl/el] suffix for baseline/endline
*				omit if variable is an identifier that could be used to match
*					across datasets, like treatment status or school code
*	--labels: 	use B/E for baseline/endline 
*				use [H/T/S]Q for head teacher/teacher/student questionnaire
*	--example: enrollment, as reported by head teacher at baseline in item #123
*		name: enroll_bl
*		label: "BHQ123: enrollment"
* 
*
*********************************************************************
qui use "$rawdata/headteacher/headteacher_endline_clean_NOPIIs.dta", clear

************************************************************************
*											   						   *
* 			   SECTION 1: Identifying information	   				   *
* 											   						   *
************************************************************************
*survey identifying information: need to mark as endline
local X "interview_starttime enumename enum_code consent ht_contact interview_endtime enum_comments formdef_version key submissiondate starttime endtime visit_date_112 piiid"
foreach x in `X' {
	qui gen `x'_el=`x'
	lab var `x'_el "`x', endline"
}


* school id
/*schoolid_bas is baseline school ID, but with issues that make it inappropriate for
	merging (see Jean Aime email to Todd 6 Aug 2019)*/
/*if so, list schools for which endline and baseline id differ*/ 
list school_105 schoolid school_code_106 reenter_schoolid schoolid_bas if school_code_106!=schoolid_bas
	
/*check that school_code_106 & reenter_schoolid are identical*/
qui destring school_code_106, gen(school_code) 
assert school_code==reenter_schoolid	
qui gen schoolname_el=school_105
lab var schoolname_el "school name, as reported in endline (school_105)"
lab val schoolname_el schoollab

/*correct school label errors, according to "Manual Checking Report.docx" */
/*check discrepancies between treatment status from schools that had to be re-coded at baseline*/
/*schools that should be treated*/
list school_105 school_code_106 group_110 if school_code_106=="0304103"|	///
											 school_code_106=="0305012"|	///
											 school_code_106=="0305034"|	///
											 school_code_106=="0403037"|	///
											 school_code_106=="0403050"|	///
											 school_code_106=="0403110"|	///
											 school_code_106=="0504114"	
qui replace group_110=1 if school_code_106=="0403110" 	
qui replace group_110=1 if school_code_106=="0403037" 	
qui replace group_110=1 if school_code_106=="0403050" 	
qui replace group_110=1 if school_code_106=="0305012"	
qui replace group_110=1 if school_code_106=="0504114"	
qui replace group_110=1 if school_code_106=="0304103"	
qui replace group_110=1 if school_code_106=="0305034"	

/*schools that should be control*/
list school_105 school_code_106 group_110 if 	school_code_106=="0301112"| ///
												school_code_106=="0304031"|	///
												school_code_106=="0403111"	
qui replace group_110=2 if school_code_106=="0301112" 
qui replace group_110=2 if school_code_106=="0304031"	
qui replace group_110=2 if school_code_106=="0403111"	

/*unassigned schools added as replacements: these are control*/
list school_105 school_code_106 group_110 if 	school_code_106=="0304102"|	///
												school_code_106=="0305112"|	///
												school_code_106=="0403121"|	///
												school_code_106=="0503118"	

												/*schools with missing treatment status*/
list school_105 school_code_106 group_110 if group_110==.
qui replace group_110=1 if school_code_106=="0506118"

/*create district & province IDs to match Census/map codes*/
qui gen province_id=.
qui replace province_id=5 if province==1 /*Eastern*/
qui replace province_id=4 if province==2 /*Northern*/
qui replace province_id=3 if province==3 /*Western*/
lab var province_id "Province ID, Census code"


qui gen district_id=.
qui replace district_id=57 if district==1 
qui replace district_id=53 if district==2 
qui replace district_id=54 if district==3 
qui replace district_id=56 if district==4 
qui replace district_id=42 if district==5 
qui replace district_id=45 if district==6 
qui replace district_id=43 if district==7 
qui replace district_id=41 if district==8 
qui replace district_id=31 if district==9 
qui replace district_id=35 if district==10 
qui replace district_id=34 if district==11 
lab var district_id "District ID, Census code"

/*school types*/
qui gen rural=(distrloc_106==1)
qui gen public=(publ_priv_108==1) /*note that there are lots of part public-part private schools*/
qui gen boarding=(board_day_109==1|board_day_109==3)
qui gen treatment=(group_110==1)	
qui replace treatment=. if group_110==.
sort district public
qui egen strata=group(district public)
lab def treatment 0 "control" 1 "treatment"
lab val treatment treatment
lab var rural "EHQ105: school located in rural district"
lab var public "EHQ108: public school"
lab var boarding "EHQ109: boarding school (including boarding/day combo)"
notes rural: "survey item is EHQ105, but variable name is distrloc_106"

/*create "_el" versions of school identifying variables to ensure these match baseline or other waves*/
local X "schoolid school_105 school_code_106 province district sector cell village distrloc_106 publ_priv_108 board_day_109 group_110 rural public boarding treatment strata"
foreach x in `X' {
	qui gen `x'_el=`x'
	lab var `x'_el "`x', endline"
}
lab var rural_el "EHQ105: school located in rural district"
lab var public_el "EHQ108: public school"
lab var boarding_el "EHQ109: boarding school (including boarding/day combo)"

/*alternate versions of treatment (see "Manual Checking Report.docx" for more details)*/
* alternate version 1: code unassigned replacement schools as missing
qui gen treatment_unassgn=treatment
qui replace treatment_unassgn=. if school_code_106=="0305112"	/*GS Muhororo: unassigned. E! status: control*/
qui replace treatment_unassgn=. if school_code_106=="0304102"	/*GS Gihira: unassigned.*/
qui replace treatment_unassgn=. if school_code_106=="0403121"	/*GS Nyakinama: unassigned.*/
qui replace treatment_unassgn=. if school_code_106=="0503118"	/*GS Nyarubuye: unassigned.*/
lab var treatment_unassgn "treatment status (unassigned replacement schools as missing)"

* alternative version 2: code schools with mismatched status between E! and initial assignment
qui gen treatment_educateassgnt=treatment
qui replace treatment_educateassgnt=1 if school_code_106=="0301112" 	/*GS Manji: control. E! status: treatment*/
qui replace treatment_educateassgnt=0 if school_code_106=="0403110" 	/*GS Kabushinge: treatment. E! status: control*/
qui replace treatment_educateassgnt=0 if school_code_106=="0403037" 	/*GS NDA Rwaza: treatment. E! status: control*/
/*additional mismatches based on E! error, not IPA assignment choice */
qui replace treatment_educateassgnt=1 if school_code_106=="0503014" 	/*ES Gasange: control. E! status: treatment*/
qui replace treatment_educateassgnt=0 if school_code_106=="0503104" 	/*GS Gasange: treatment. E! status: control*/
lab var treatment_educateassgnt "treatment status (based on Educate! records, not initial assignment)"
foreach x in unassgn educateassgnt {
	lab val treatment_`x' treatment
}

**********************************************************************
*											   				 		 *
* 		SECTION 2: Head Teacher/Respondent Background	 	 		 *
*													 	 	 		 *
**********************************************************************
/*head teacher/respondent background*/
foreach x in first family {
	qui gen `x'_name_200_el=`x'_name_200
	lab var `x'_name_200_el "EHQ200: `x' name"
} 
qui gen ht_el=(position_201==1)
qui gen ht_female_el=(gender_202==1)
qui gen ht_age_el=age_203 
qui gen ht_exper_el=years_ht_exp_204
qui gen ht_exper_teach_el=years_teach_exp_205
foreach x in age exper exper_teach {
	qui replace ht_`x'_el=. if ht_`x'_el==-99
}
qui gen ht_bach_el=(educ_level_206==3)
qui gen ht_mast_el=(educ_level_206==4)
lab var ht_el "EHQ201: head teacher responded to questionnaire"
lab var ht_female_el "EHQ202: head teacher (or respondent) is female"
lab var ht_age_el "EHQ203: head teacher (or respondent) age"
lab var ht_exper_el "EHQ204: head teacher experience (less than 1yr coded as 0)"
lab var ht_exper_teach_el "EHQ205: head teacher experience as a teacher"
lab var ht_bach_el "EHQ206: head teacher has bachelor's (A0)"
lab var ht_mast_el "EHQ206: head teacher has master's"

/*school enrollment*/
forval g=1/6 {
	foreach s in male female {
		if ("`s'"=="male") local ss "m"
		else if ("`s'"=="female") local ss "f"
		qui gen enroll_s`g'_`ss'_el=s`g'_`s'
		qui replace enroll_s`g'_`ss'_el=0 if s`g'_`s'<0
		lab var enroll_s`g'_`ss'_el "EHQ207: school enrollment, S`g', `s'"
	}
	qui gen enroll_s`g'_el=enroll_s`g'_m_el+enroll_s`g'_f_el
	qui gen enroll_s`g'_fpct_el=enroll_s`g'_f_el/enroll_s`g'_el
	lab var enroll_s`g'_el "EHQ207: school enrollment, S`g'"
	lab var enroll_s`g'_fpct_el "EHQ207: school enrollment, S`g', proportion female"
}
qui gen enroll_ls_el=enroll_s1_el+enroll_s2_el+enroll_s3_el
qui gen enroll_us_el=enroll_s4_el+enroll_s5_el+enroll_s6_el
qui gen enroll_s_el=enroll_ls_el+enroll_us_el
qui gen enroll_total_el=enroll_ls_el+enroll_us_el
foreach s in m f {
	qui gen enroll_ls_`s'_el=enroll_s1_`s'_el+enroll_s2_`s'_el+enroll_s3_`s'_el
	qui gen enroll_us_`s'_el=enroll_s4_`s'_el+enroll_s5_`s'_el+enroll_s6_`s'_el 
	qui gen enroll_s_`s'_el=enroll_ls_`s'_el+enroll_us_`s'_el
}
foreach x in s ls us {
	qui gen enroll_`x'_fpct_el=enroll_`x'_f_el/enroll_`x'_el
}
qui gen all_female_el=(enroll_us_m_el==0 & enroll_us_f_el>0)
qui gen all_male_el=(enroll_us_f_el==0 & enroll_us_m_el>0)
lab var enroll_ls_el "EHQ207: school enrollment, lower secondary"
lab var enroll_ls_m_el "EHQ207: school enrollment, lower secondary, male"
lab var enroll_ls_f_el "EHQ207: school enrollment, lower secondary, female"
lab var enroll_ls_fpct_el "EHQ207: school enrollment, lower secondary, proportion female"
lab var enroll_us_el "EHQ207: school enrollment, upper secondary"
lab var enroll_us_m_el "EHQ207: school enrollment, upper secondary, male"
lab var enroll_us_f_el "EHQ207: school enrollment, upper secondary, female"
lab var enroll_us_fpct_el "EHQ207: school enrollment, upper secondary, proportion female"
lab var enroll_s_el "EHQ207: school enrollment, secondary"
lab var enroll_s_m_el "EHQ207: school enrollment, secondary, male"
lab var enroll_s_f_el "EHQ207: school enrollment, secondary, female"
lab var enroll_s_fpct_el "EHQ207: school enrollment, secondary, proportion female"
lab var enroll_total_el "EHQ207: school enrollment, total"
lab var all_female_el "EHQ207: all female school (based on S4-S6 enrollment)"
lab var all_male_el "EHQ207: all male school (based on S4-S6 enrollment)"

/*teacher personnel*/
foreach x in m f {
	qui gen teach_p_`x'_el=primary_teach_`x'
	qui gen teach_ls_`x'_el=lower_s_teach_`x'
	qui gen teach_us_`x'_el=upper_s_teach_`x'
	foreach l in p ls us {
		qui replace teach_`l'_`x'_el=0 if teach_`l'_`x'_el<0
	}
}
foreach l in p ls us {
	qui gen teach_`l'_el=teach_`l'_m_el+teach_`l'_f_el
	qui gen teach_`l'_fpct_el=teach_`l'_f_el/teach_`l'_el
}
qui gen teach_total_el=teach_p_el+teach_ls_el+teach_us_el 
/*note also variable "totat_teachers", which is reported total but not constrained to be sum of level-specific totals*/
lab var teach_p_el "EHQ208: teachers, primary"
lab var teach_p_m_el "EHQ208: male teachers, primary"
lab var teach_p_f_el "EHQ208: female teachers, primary"
lab var teach_p_fpct_el "EHQ208: proportion female teachers, primary"
lab var teach_ls_el "EHQ208: teachers, lower secondary"
lab var teach_ls_m_el "EHQ208: male teachers, lower secondary"
lab var teach_ls_f_el "EHQ208: female teachers, lower secondary"
lab var teach_ls_fpct_el "EHQ208: proportion female teachers, lower secondary"
lab var teach_us_el "EHQ208: teachers, upper secondary"
lab var teach_us_m_el "EHQ208: male teachers, upper secondary"
lab var teach_us_f_el "EHQ208: female teachers, upper secondary"
lab var teach_us_fpct_el "EHQ208: proportion female teachers, upper secondary"
lab var teach_total_el "EHQ208: total number of teachers in school (sum of all levels reported)"

/*entrepreneurship teachers*/
qui gen teach_entr_el=numteachers
lab var teach_entr_el "EHQ209: number of entrepreneurship teachers"
order lev_taught_209__?_?
forval g=1/6 {
	/*counts of entrepreneurship teachers by grade*/
	qui egen teach_entr_s`g'_el=rowtotal(lev_taught_209__`g'_1-lev_taught_209__`g'_7)
	qui gen teach_entr_s`g'_m_el=0
	qui gen teach_entr_s`g'_f_el=0
	qui gen teach_entr_s`g'_qual_el=0
	qui gen teach_entr_s`g'_pt_el=0
	qui gen teach_entr_s`g'_m_qual_el=0
	qui gen teach_entr_s`g'_f_qual_el=0
	lab var teach_entr_s`g'_el "EHQ209: number of S`g' entrepreneurship teachers (max 7)"
	lab var teach_entr_s`g'_m_el "EHQ209: number of male S`g' entrepreneurship teachers (max 7)"
	lab var teach_entr_s`g'_f_el "EHQ209: number of female S`g' entrepreneurship teachers (max 7)"
	lab var teach_entr_s`g'_qual_el "EHQ209: number of qualified S`g' entrepreneurship teachers (max 7)"
	lab var teach_entr_s`g'_pt_el "EHQ209: number of part-time S`g' entrepreneurship teachers (max 7)"
	lab var teach_entr_s`g'_m_el "EHQ209: number of qualified male S`g' entrepreneurship teachers (max 7)"
	lab var teach_entr_s`g'_f_el "EHQ209: number of qualified female S`g' entrepreneurship teachers (max 7)"
	forval i=1/7 {
		qui replace teach_entr_s`g'_m_el=teach_entr_s`g'_m_el+1 if lev_taught_209__`g'_`i'==1 & gender_209__`i'==1
		qui replace teach_entr_s`g'_f_el=teach_entr_s`g'_f_el+1 if lev_taught_209__`g'_`i'==1 & gender_209__`i'==2
		qui replace teach_entr_s`g'_qual_el=teach_entr_s`g'_qual_el+1 if lev_taught_209__`g'_`i'==1 & teach_qual_209__`i'==1
		qui replace teach_entr_s`g'_pt_el=teach_entr_s`g'_pt_el+1 if lev_taught_209__`g'_`i'==1 & full_part_time_209__`i'==2
		qui replace teach_entr_s`g'_m_qual_el=teach_entr_s`g'_m_qual_el+1 if lev_taught_209__`g'_`i'==1 & gender_209__`i'==1 & teach_qual_209__`i'==1
		qui replace teach_entr_s`g'_f_qual_el=teach_entr_s`g'_f_qual_el+1 if lev_taught_209__`g'_`i'==1 & gender_209__`i'==2 & teach_qual_209__`i'==1
	}
	/*proportions of entrepreneurship teachers by grade*/
	qui gen teach_entr_s`g'_fpct_el=teach_entr_s`g'_f_el/teach_entr_s`g'_el
	qui gen teach_entr_s`g'_qualpct_el=teach_entr_s`g'_qual_el/teach_entr_s`g'_el
	qui gen teach_entr_s`g'_ptpct_el=teach_entr_s`g'_pt_el/teach_entr_s`g'_el
	qui gen teach_entr_s`g'_m_qualpct_el=teach_entr_s`g'_m_qual_el/teach_entr_s`g'_m_el
	qui gen teach_entr_s`g'_f_qualpct_el=teach_entr_s`g'_f_qual_el/teach_entr_s`g'_f_el
	lab var teach_entr_s`g'_fpct_el "EHQ209: proportion female S`g' entrepreneurship teachers (of up to 7 listed)"
	lab var teach_entr_s`g'_qualpct_el "EHQ209: proportion qualified S`g' entrepreneurship teachers (of up to 7 listed)"
	lab var teach_entr_s`g'_ptpct_el "EHQ209: proportion part-time S`g' entrepreneurship teachers (of up to 7 listed)"
	lab var teach_entr_s`g'_m_qualpct_el "EHQ209: proportion qualified S`g' male entrepreneurship teachers (of up to 7 listed)"
	lab var teach_entr_s`g'_f_qualpct_el "EHQ209: proportion qualified S`g' female entrepreneurship teachers (of up to 7 listed)"
}

/*counts and percentages of entrepreneurship teachers, across all grades*/
order gender_209__? teach_qual_209__? full_part_time_209__?
qui egen teach_entr_m_el=anycount(gender_209__1-gender_209__7), v(1)
qui egen teach_entr_f_el=anycount(gender_209__1-gender_209__7), v(2)
qui egen teach_entr_qual_el=rowtotal(teach_qual_209__1-teach_qual_209__7)
qui egen teach_entr_pt_el=anycount(full_part_time_209__1-full_part_time_209__7), v(2)
qui gen teach_entr_m_qual_el=.
qui gen teach_entr_f_qual_el=.
qui replace teach_entr_m_qual_el=0 if teach_entr_m_el>0
qui replace teach_entr_f_qual_el=0 if teach_entr_f_el>0
forval i=1/5 {
	qui replace teach_entr_m_qual_el=teach_entr_m_qual_el+1 if gender_209__`i'==1 & teach_qual_209__`i'==1
	qui replace teach_entr_f_qual_el=teach_entr_f_qual_el+1 if gender_209__`i'==2 & teach_qual_209__`i'==1
}
foreach x in f qual pt {
	qui gen teach_entr_`x'pct_el=teach_entr_`x'_el/teach_entr_el
}
foreach x in m f {
	qui gen teach_entr_`x'_qualpct_el=teach_entr_`x'_qual_el/teach_entr_`x'_el
}
lab var teach_entr_m_el "EHQ209: number of male entrepreneurship teachers (max 7)"
lab var teach_entr_f_el "EHQ209: number of female entrepreneurship teachers (max 7)"
lab var teach_entr_qual_el "EHQ209: number of qualified entrepreneurship teachers (max 7)"
lab var teach_entr_pt_el "EHQ209: number of part-time entrepreneurship teachers (max 7)"
lab var teach_entr_fpct_el "EHQ209: proportion female entrepreneurship teachers"
lab var teach_entr_qualpct_el "EHQ209: proportion qualified entrepreneurship teachers"
lab var teach_entr_ptpct_el "EHQ209: proportion part-time entrepreneurship teachers"
lab var teach_entr_m_qualpct_el "EHQ209: proportion qualified male entrepreneurship teachers"
lab var teach_entr_f_qualpct_el "EHQ209: proportion qualified female entrepreneurship teachers"

/*number of additional entrepreneurship grades taught by S6 entrepreneurship teachers*/
forval i=1/7 {
	qui gen teach_entr_s6_oth`i'_el=.
	qui replace teach_entr_s6_oth`i'_el=0 if lev_taught_209__6_`i'==1
	forval g=1/5 {
		qui replace teach_entr_s6_oth`i'_el=teach_entr_s6_oth`i'_el+1 if lev_taught_209__`g'_`i'==1
	}
	lab var teach_entr_s6_oth`i'_el "EHQ209: number of entrepreneurship grades in addition to S6 taught by teacher `i'/7"
}
order teach_entr_s6_oth?_el
qui egen teach_entr_s6_othavg_el=rowmean(teach_entr_s6_oth1_el-teach_entr_s6_oth7_el)
lab var teach_entr_s6_othavg_el "EHQ209: avg. number of entrepreneurship grades taught in addition to S6 at school"

/*teacher absences*/
qui gen attendance_record_el=(rec_attend_opts_210==2)
forval i=1/3 { /*number of absences: sum over 3 Tuesdays, replacing missing with zeroes, but code avg. as missing if all reports missing*/
	qui gen x`i'=abs_tues`i'_211
	qui replace x`i'=. if abs_tues`i'_211<0 
}
qui egen xmiss=rowmiss(x1 x2 x3)
forval i=1/3 { /*number of absences: sum over 3 Tuesdays, replacing missing with zeroes, but code avg. as missing if all reports missing*/
	qui replace x`i'=0 if abs_tues`i'_211<0 
}
qui egen teach_absent_avg_el=rowmean(x1 x2 x3)
qui replace teach_absent_avg_el=. if xmiss==3
drop x1 x2 x3 xmiss
qui gen teach_absent_pct_el=teach_absent_avg_el/teach_total_el
foreach x in avg pct {
	qui gen teach_absent_`x'_rec_el=teach_absent_`x'_el if attendance_record_el==1
}
lab var attendance_record_el "EHQ210: showed teacher attendance records"
lab var teach_absent_avg_el "EHQ211: teacher absences, average of last 3 Tuesdays"
lab var teach_absent_pct_el "EHQ211/EHQ209: teacher absences, proportion of total"
lab var teach_absent_avg_rec_el "EHQ211: teacher absences, avg last 3 Tuesdays (conditional on showing records)"
lab var teach_absent_pct_rec_el "EHQ211/EHQ209: teacher absences, proportion of total (conditional on showing records)"

/*Skills Lab on timetable*/
qui gen ht_skillslab_timetable_el=(timetable_212==3)
qui gen ht_dblperiod_timetable_el=(timetable_212==2|timetable_212==3)
lab var ht_skillslab_timetable_el "EHQ212: verified Skills Lab on timetable"
lab var ht_dblperiod_timetable_el "EHQ212: verified Skills Lab or entrepreneurship double period on timetable"

**********************************************************************
*											   				 		 *
* 		SECTION 3: School Finances and Resources	 	 	 		 *
* 														     		 *
**********************************************************************
qui gen fees_el=(fees_parents_300==1)
qui gen fees_amt_el=amt_fees_301 if fees_el==1
qui replace fees_amt_el=. if fees_amt_el<0
foreach x in textb money {
	foreach s in govt ngo committee {
		qui gen `x'_`s'_el=`x'_`s'_302
		qui replace `x'_`s'_el=0 if `x'_`s'_el<0
		lab var `x'_`s'_el "EHQ302: `x' received from `s'"
	}
	qui gen `x'_rec_el=`x'_govt_el+`x'_ngo_el+`x'_committee_el
	qui gen `x'_rec_pc_el=`x'_rec_el/enroll_total_el
	lab var `x'_rec_el "EHQ302: `x' received from all sources"
	lab var `x'_rec_pc_el "EHQ302: `x' received from all sources, per student"
}
qui gen fees_amt_usd_el=fees_amt_el/`xrate'
lab var fees_el "EHQ300: school collects fees"
lab var fees_amt_el "EHQ301: annual fees per student (FRW)"
lab var fees_amt_usd_el "EHQ301: annual fees per student (USD)"

**********************************************************************
*											   				 		 *
* 					SECTION 4: School Management	 	 	 		 *
* 														     		 *
**********************************************************************
/*see also: opening/closing/break times, q400*/
qui gen lead_pro_dev_reb_el=(lead_pro_dev==1)
qui gen lead_pro_dev_educate_el=(lead_pro_dev==2)
qui gen lead_pro_dev_rebandeducate_el=(lead_pro_dev==3)
qui gen lead_pro_dev_e_or_rebande_el=(lead_pro_dev==2|lead_pro_dev==3)
lab var lead_pro_dev_reb_el "EHQ401: REB leads teacher professional development" 
lab var lead_pro_dev_educate_el "EHQ401: Educate! leads teacher professional development" 
lab var lead_pro_dev_rebandeducate_el "EHQ401: REB & Educate! lead teacher professional development" 
lab var lead_pro_dev_e_or_rebande_el "EHQ401: E! or REB & E! lead teacher professional development" 
qui gen teach_observe_el=(class_obs==4)
lab var teach_observe_el "EHQ405: showed records of classroom observations"

**********************************************************************
*											   				 		 *
* 			SECTION 5: Pedagogy and competence-based curriculum	 	 *
* 														     		 *
**********************************************************************
/* classify these methods as "active learning":
	--question & answer
	--small group work
	--games
	--activities outside classroom
	--experiment
	--student portfolio (not listed for most/least comfortable, but listed for entreneurship effectiveness)*/
/*code REMOVES discussion and practive exercises, as these did not appear in pre-analysis plan or JDE Registered Report*/
local active_mostcomf "teach_meth_mostcomf_2 teach_meth_mostcomf_4 teach_meth_mostcomf_5 teach_meth_mostcomf_7 teach_meth_mostcomf_11"
local active_leastcomf "teach_meth_leastcomf_2 teach_meth_leastcomf_4 teach_meth_leastcomf_5 teach_meth_leastcomf_7 teach_meth_leastcomf_11"
local active_entr_mostef "meth_3_607_2 meth_3_607_4 meth_3_607_5 meth_3_607_7 meth_3_607_11 meth_3_607_12"
local active_entr_leastef "meth_3_605_2 meth_3_605_4 meth_3_605_5 meth_3_605_7 meth_3_605_11 meth_3_605_12"
foreach x in mostcomf leastcomf entr_mostef entr_leastef {		
	qui egen ht_pedagogy_actv_`x'_el=rowtotal(`active_`x'')
}
lab var ht_pedagogy_actv_mostcomf_el "EHQ500: head teacher: # active learning strategies among 3 most comfortable methods"	
lab var ht_pedagogy_actv_leastcomf_el "EHQ501: head teacher: # active learning strategies among 3 least comfortable methods"	
lab var ht_pedagogy_actv_entr_mostef_el "EHQ507: head teacher: # active learning strategies among 3 most effective for entrepreneurship"
lab var ht_pedagogy_actv_entr_leastef_el "EHQ508: head teacher: # active learning strategies among 3 least effective for entrepreneurship"

qui gen ht_pedagogy_active_el=(ht_pedagogy_actv_entr_mostef_el>=2 & ht_pedagogy_actv_entr_mostef_el!=.)
qui gen ht_pedagogy_active_ineff_el=(ht_pedagogy_actv_entr_leastef_el<2 & ht_pedagogy_actv_entr_leastef_el!=.)
qui gen ht_pedagogy_active_index_el=ht_pedagogy_actv_entr_mostef_el + (3-ht_pedagogy_actv_entr_leastef_el)
lab var ht_pedagogy_active_el "EHQ507: HT interactive pedagogy at least 2 of 3 most effective"
lab var ht_pedagogy_active_ineff_el "EHQ508: HT interactive pedagogy 0 or 1 (of 3) least effective"
lab var ht_pedagogy_active_index_el "EHQ507-508: HT interactive pedagogy support index (0=least supportive, 6=most supportive)"

* alternative classification 
/* classify these methods as "active learning":
	--small group work
	--games
	--research
	--activities outside classroom
	--practice exercises
	--experiment
	--student portfolio (not listed for most/least comfortable, but listed for entreneurship effectiveness)*/
local active2_mostcomf "teach_meth_mostcomf_4 teach_meth_mostcomf_5 teach_meth_mostcomf_7 teach_meth_mostcomf_9 teach_meth_mostcomf_10 teach_meth_mostcomf_11"
local active2_leastcomf "teach_meth_leastcomf_4 teach_meth_leastcomf_5 teach_meth_leastcomf_7 teach_meth_leastcomf_9 teach_meth_leastcomf_10 teach_meth_leastcomf_11"
local active2_entr_mostef "meth_3_607_4 meth_3_607_5 meth_3_607_7 meth_3_607_9 meth_3_607_10 meth_3_607_11 meth_3_607_12"
local active2_entr_leastef "meth_3_605_4 meth_3_605_5 meth_3_605_7 meth_3_605_9 meth_3_605_10 meth_3_605_11 meth_3_605_12"
foreach x in mostcomf leastcomf entr_mostef entr_leastef {		
	qui egen ht_pedgy_actv2_`x'_el=rowtotal(`active_`x'')		
	notes ht_pedgy_actv2_`x'_el: "active (E! definition) includes small group work, games, research, activities outside classroom, practice exercises, experiment, student portfolio"
}
lab var ht_pedgy_actv2_mostcomf_el "EHQ500: HT: # active learning strategies among 3 most comfortable methods (E! definition)"	
lab var ht_pedgy_actv2_leastcomf_el "EHQ501: HT: # active learning strategies among 3 least comfortable methods (E! definition)"	
lab var ht_pedgy_actv2_entr_mostef_el "EHQ507: HT: # active learning strategies among 3 most effective for entrepreneurship (E! definition)"
lab var ht_pedgy_actv2_entr_leastef_el "EHQ508: HT: # active learning strategies among 3 least effective for entrepreneurship (E! definition)"
	
/*HT perceptions of teacher goals and training - Not very informative because was supposed to be ranking, but no ranks given*/
qui gen goalteach_shld_knowledge_el=(goal_teach_602_1==1)
qui gen goalteach_shld_skill_el=(goal_teach_602_2==1)
qui gen goalteach_shld_attitude_el=(goal_teach_602_3==1)
qui gen goalteach_shld_exam_el=(goal_teach_602_4==1)
qui gen goalteach_shld_knoworexam_el=(goal_teach_602_1==1|goal_teach_602_4==1)
qui gen goalteach_shld_attdorskill_el=(goal_teach_602_2==1|goal_teach_602_3==1)
lab var goalteach_shld_knowledge_el "EHQ502: teachers' goal should be develop student knowledge"
lab var goalteach_shld_skill_el "EHQ502: teachers' goal should be develop student skills"
lab var goalteach_shld_attitude_el "EHQ502: teachers' goal should be develop student attitudes"
lab var goalteach_shld_exam_el "EHQ502: teachers' goal should be help students pass exams"
lab var goalteach_shld_knoworexam_el "EHQ502: teachers' goal should be develop student knowledge or pass exams"
lab var goalteach_shld_attdorskill_el "EHQ502: teachers' goal should be develop student attitudes or skills"

/*Skills Lab knowledge: EHQ505-506. Not asked at endline.*/

* save data
qui gen insample_el=1
lab var insample_el "in endline sample"

qui compress
lab data "Head teacher endline survey (2018), modified from cleaned data"
qui save "$cleandata/headteacher_endline_clean_jde.dta", replace	

local end=`"$S_TIME"' 
di "`start'"
di "`end'"
